#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int N = 100010;

int n, m;
vector<pii> ans;

int main() {
  freopen("bishop.in", "r", stdin);
  freopen("bishop.out", "w", stdout);
  cin >> n >> m;
  bool flag = (n > m);
  if (n == 1 && m == 1) {
    cout << "1\n";
    cout << "1 1\n";
    return 0;
  }
  if (n > m) swap(n, m);
  if (n & 1) {
    if (n == m) {
      rep (i, 2, n) ans.emplace_back(i, 1);
      rep (i, 2, n) ans.emplace_back(i, m);
    } else if (m == n + 1) {
      rep (i, 1, n) ans.emplace_back(i, 1);
      rep (i, 1, n) ans.emplace_back(i, m);
    } else {
      rep (i, 1, n) ans.emplace_back(i, 1);
      rep (i, 1, n) ans.emplace_back(i, m);
      int pos = n / 2 + 2;
      rep (i, 1, m - n - 1) ans.emplace_back((n + 1) / 2, pos), pos++;
    }
  } else {
    if (n == m) {
      rep (i, 2, n) ans.emplace_back(i, 1);
      rep (i, 2, n) ans.emplace_back(i, m);
    } else if (m == n + 1) {
      rep (i, 1, n) ans.emplace_back(i, 1);
      rep (i, 1, n) ans.emplace_back(i, m);
    } else if (m & 1) {
      rep (i, 1, n) ans.emplace_back(i, 1);
      rep (i, 1, n) ans.emplace_back(i, m);
      int pos = n / 2 + 2;
      rep (i, 1, (m - n) / 2) {
        ans.emplace_back(n / 2, pos);
        ans.emplace_back(n / 2 + 1, pos);
        pos += 2;
      }
    } else {
      rep (i, 2, n) ans.emplace_back(i, 1);
      rep (i, 2, n) ans.emplace_back(i, m);
      int pos = n / 2 + 1;
      rep (i, 1, m - n) ans.emplace_back(n / 2 + 1, pos), pos++;
    }
  }
  cout << SZ(ans) << '\n';
  for (auto info : ans) {
    if (flag) swap(info.fi, info.se);
    cout << info.fi << " " << info.se << "\n";
  }
}